package com.fwj.gmall.product.controller;

import com.fwj.gmall.model.product.BaseCategory1;
import com.fwj.gmall.model.product.BaseCategory2;
import com.fwj.gmall.model.product.BaseCategory3;
import com.fwj.gmall.product.service.CategoryService;
import com.fwj.gmall.result.Result;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@RequestMapping("/admin/product/")
@Api("分类属性接口")
public class CategoryController {


    @Autowired
    CategoryService categoryService;

    @ApiOperation("获取一级分类")
    @GetMapping("getCategory1")
    public Result getCategory1() {

        List<BaseCategory1> category1List = categoryService.getCategory1();

        return Result.ok(category1List);
    }

    @ApiOperation("获取二级分类")
    @GetMapping("getCategory2/{category1Id}")
    public Result getCategory2(@PathVariable("category1Id") Long category1Id) {

        List<BaseCategory2> category2List = categoryService.getCategory2(category1Id);

        return Result.ok(category2List);
    }

    @ApiOperation("获取三级分类")
    @GetMapping("getCategory3/{category2Id}")
    public Result getCategory3(@PathVariable("category2Id") Long category2Id) {

        List<BaseCategory3> category3List = categoryService.getCategory3(category2Id);

        return Result.ok(category3List);
    }


}
